/*
 * Represents a Bid made on an Item in the Auction Central System
 * @author Kevin
 * @version 1.0
 * @date Winter 2014
 */

package model;

import java.util.Calendar;

/**
 * Represents a Bid made on an Item in the Auction Central System.
 * 
 * @author Kevin
 * @version 1.0
 * @date Winter 2014
 */
public class Bid {
	
	/** Dollar amount of the bid */
	private double my_amount;

	/** Who made the bid */
	private Bidder my_bidder;

	/** Which item was bid on */
	private Item my_item;

	/** 
	 * Construct a bid object. 
	 * 
	 * @pre the_item != null
	 * @pre the_bidder != null
	 * 
	 * @param the_item The Item.
	 * @param the_bidder The Bidder.
	 * @param d The bid amount.
	 */
	public Bid (final Item the_item, final Bidder the_bidder, final double d) {
		my_amount = d;
		setBidder(the_bidder);
		my_item = the_item;
	}

	/** 
	 * Get the amount of the bid.
	 * 
	 * @return dollar value of the bid.
	 */
	public double getBid() {
		return my_amount;
	}

	/**
	 * Sets the current bid to a new value.
	 * 
	 * @pre bid > 0
	 * @param bid the new dollar amount to be held
	 */
	public void setBid(float bid) {
		my_amount = bid;
	}

	/**
	 * Tells whether or not the bid is able to be cancelled.
	 * 
	 * @return TRUE if can be cancelled
	 *         FALSE otherwise
	 */
	public boolean canCancel() {
		boolean result = false;
		Calendar temp = Calendar.getInstance();
		temp.add(Calendar.DAY_OF_MONTH, 1);
		if(my_item.getAuction().getDate().after(temp.getTime() )) result = true;;
		return result;
		//have time for 24 hours before auction begins
	}

	/**
	 * Returns the bidder.
	 * 
	 * @return the bidder
	 */
	public Bidder getBidder() {
		return my_bidder;
	}

	/**
	 * Sets the Bidder.
	 * 
	 * @pre bidder != null
	 * @param bidder the bidder to set
	 */
	public void setBidder(Bidder bidder) {
		this.my_bidder = bidder;
	}

	/**
	 * Returns the item this bid was placed on.
	 * 
	 * @return The item this bid was placed on
	 */
	public Item getItem() {
		return my_item;
	}

	/**
	 * Returns a String representation of the Bid object.
	 * 
	 * @return a String representation.
	 */
	public String toString() {
		return my_item.getMyItemNumber() + "~" + my_amount;
	}
}
